package com.shenmazong.servereduschool.service.impl;

import com.shenmazong.servereduschool.entity.TbStage;
import com.shenmazong.servereduschool.mapper.TbStageMapper;
import com.shenmazong.servereduschool.service.ITbStageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 阶段（课程表）——suliven 服务实现类
 * </p>
 *
 * @author 关好帅
 * @since 2021-09-22
 */
@Service
public class TbStageServiceImpl extends ServiceImpl<TbStageMapper, TbStage> implements ITbStageService {

    @Autowired
    private TbStageMapper tbStageMapper;

    @Override
    public ResultResponse createStage(TbStage stage) {
        try {
            tbStageMapper.insert(stage);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteStage(BatchChooseIdVo idVo) {
        if(idVo.getIds().size()<=0){
            return ResultResponse.FAILED("请至少选择一个删除");
        }
        try {
            tbStageMapper.deleteBatchIds(idVo.getIds());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse updateStage(TbStage stage) {
        try {
            tbStageMapper.updateById(stage);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }
}
